﻿/*****************************************************************//**
 * @file    FITKGraphObjectSpringPoint2PointPreview.h
 * @brief   Graph object for previewing point to point spring.
 *  
 * @author  ChengHaotian (yeguangbaozi@foxmail.com)
 * @date    2024-06-21
 *********************************************************************/

#ifndef __FITKGRAPHOBJECTSPRINGPOINT2POINTPREVIEW_H__
#define __FITKGRAPHOBJECTSPRINGPOINT2POINTPREVIEW_H__

#include "FITKGraphObjectMarkBase.h"

#include "FITKVTKGraphAdaptorAPI.h"

// Forward declaration
class vtkPoints;
class vtkCellArray;
class vtkPolyData;
class vtkUnstructuredGrid;
class vtkUnsignedCharArray;

class FITKGraphActor;

namespace Interface
{
    class FITKAbaSpringDashpotPoint2Point;
}

namespace Exchange
{
    /**
     * @brief   Graph object for previewing point to point spring.
     * @author  ChengHaotian (yeguangbaozi@foxmail.com)
     * @date    2024-06-21
     */
    class FITKVTKGRAPHADAPTORAPI FITKGraphObjectSpringPoint2PointPreview : public FITKGraphObjectMarkBase
    {
        // Regist
        FITKGraphObjectRegist(FITKGraphObjectSpringPoint2PointPreview, FITKGraphObjectMarkBase);
        FITKCLASS(Exchange, FITKGraphObjectSpringPoint2PointPreview);

    public:
        /**
         * @brief   Constructor.
         * @param   caseData: The case data
         * @param   springData: The spring data object
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        FITKGraphObjectSpringPoint2PointPreview(AbaqusData::FITKDataCase* caseData, Interface::FITKAbaSpringDashpotPoint2Point* springData);

        /**
         * @brief   Destructor.[virtual]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        virtual ~FITKGraphObjectSpringPoint2PointPreview();

        /**
         * @brief   Show or hide graph object.[override]
         * @param   visibility: The visibility of graph object
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        void setVisible(bool visibility) override;

        /**
         * @brief   Highlight the interactions or constraint graph actors.[override]
         * @param   color: The given color for highlighting this time[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        void highlight(QColor color = QColor()) override;

        /**
         * @brief   Dis-highlight the interactions or constraint graph actors.[override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        void disHighlight() override;

        /**
         * @brief   Highlight part of the spring graph object by the given indice of spring pair.[override]
         * @param   details: The details about highlighting.( The indice of spring pair need to be highlighted. )[default]
         * @param   color: The given color for highlighting this time[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        void advanceHighlight(QVariant details, QColor color = QColor()) override;

        /**
         * @brief   Dis-advance highlight.[override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        void disAdvanceHighlight() override;

        /**
         * @brief   Update all graph actors.[override]
         * @param   forceUpdate: Force update[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        void update(bool forceUpdate = false) override;

        /**
         * @brief   Update the visibility with data object's visibility.[override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        void updateVisibility() override;

    private:
        /**
         * @brief   Initialize.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        void init();

        /**
         * @brief   Initialize the actors.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        void initActors();

        /**
         * @brief   Reset the advance data.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-02
         */
        void clearAdvanceData();

        /**
         * @brief   Clear the data.[override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        void clearData() override;

        /**
         * @brief   Generate interactions or constraint actor.[override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        void generateGraph() override;

        /**
         * @brief   Generate the poly data for the spring.
         * @param   springData: The spring data object
         * @return  Is OK
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        bool generatePolyData(Interface::FITKAbaSpringDashpotPoint2Point* springData);

    private:
        /**
         * @brief   The points data for spring glyphs.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        vtkPoints* m_pointsPt{ nullptr };

        /**
         * @brief   The grid data for interactions or constraint.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        vtkUnstructuredGrid* m_ugridPt{ nullptr };

        /**
         * @brief   The points data for spring lines.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        vtkPoints* m_pointsLine{ nullptr };

        /**
         * @brief   The grid data for spring lines.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        vtkUnstructuredGrid* m_ugridLine{ nullptr };

        /**
         * @brief   The color array for points.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        vtkUnsignedCharArray* m_colorArrayPt{ nullptr };

        /**
         * @brief   The graph actor for spring points.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        FITKGraphActor* m_fActorPt{ nullptr };

        /**
         * @brief   The graph actor for spring lines.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        FITKGraphActor* m_fActorLine{ nullptr };

        /**
         * @brief   The points data for advanced-highlighting.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-02
         */
        vtkPoints* m_pointsAdv{ nullptr };

        /**
         * @brief   The grid data for advanced-highlighting.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-02
         */
        vtkUnstructuredGrid* m_ugridAdv{ nullptr };

        /**
         * @brief   The graph actor for advanced-highlighting the spring lines.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-02
         */
        FITKGraphActor* m_fActorAdv{ nullptr };

        /**
         * @brief   The color of first point of each line.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        QColor m_startColor = QColor(255, 0, 0);

        /**
         * @brief   The color of second point of each line.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-21
         */
        QColor m_endColor = QColor(255, 0, 255); 

        /**
         * @brief   The point size.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-02
         */
        int m_vertexSize = 10;

    };
}   // namespace Exchange

#endif // __FITKGRAPHOBJECTSPRINGPOINT2POINTPREVIEW_H__
